package com.example.shopping_mall.base;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.shopping_mall.R;
import com.example.shopping_mall.adapter.MineLocationAdapter;
import com.example.shopping_mall.application.MineOrderPresenter;
import com.example.shopping_mall.bean.LocationData;
import com.example.shopping_mall.http.IMineOrderPresenter;

import java.util.ArrayList;
import java.util.List;

public class MineLocationActivity extends AppCompatActivity {

    RecyclerView mineLocationRV;

    private IMineOrderPresenter mineOrderPresenter;
    List<LocationData> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_location);
        mineOrderPresenter = new MineOrderPresenter(this);
        initView();
        initFinish();
    }

    private void initFinish() {
        findViewById(R.id.orderLocationFinish).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {

        mineLocationRV = findViewById(R.id.mineLocationRV);
        mineLocationRV.setLayoutManager(new LinearLayoutManager(this));

        mineOrderPresenter.requestLonction(new MineOrderPresenter.OnMineLonctionListener() {
            @Override
            public void onMineLonction(LocationData locationData) {

                Log.d("TAG", "onMineLonction: " + locationData.getName());
                LocationData data = new LocationData();
                data.setId(locationData.getId());
                data.setAddressName(locationData.getAddressName());
                data.setSendStatus(locationData.getSendStatus());
                data.setReceiveStatus(locationData.getReceiveStatus());
                data.setName(locationData.getName());
                data.setPhone(locationData.getPhone());
                data.setProvince(locationData.getProvince() == null ? "" : locationData.getProvince());
                data.setCity(locationData.getCity() == null ? "" : locationData.getCity());
                data.setRegion(locationData.getRegion() == null ? "" : locationData.getRegion());
                data.setDetailAddress(locationData.getDetailAddress());
                list.add(data);


                MineLocationAdapter adapter = new MineLocationAdapter(list, MineLocationActivity.this);
                mineLocationRV.setAdapter(adapter);
            }
        });
    }
}